package com.thinkgsp.jxc.model;

import java.io.Serializable;
import java.math.BigDecimal;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

/**
 * 单据明细类
 * @author evan
 *
 */

public class BillDetail extends BaseModel implements Serializable {

	private static final long serialVersionUID = 1899323269159694828L;

	private Long id;
	private Long billId;
	private Integer productId;
	private Long batchNoId;
	private Integer invAddId;
	private Integer direct;
	private BigDecimal quantity;
	private BigDecimal taxRate = new BigDecimal("0.17");
	private BigDecimal price;
	private BigDecimal settlePrice;
	private BigDecimal costPrice = BigDecimal.ZERO;
	private String remark;
	
	private Product product;
	private ProductBatchNo batchNo;
	private InventoryAdd invAdd;
	
	/**
	 * 单据明细ID
	 * @return
	 */
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	/**
	 * 单据ID
	 * @return
	 */
	public Long getBillId() {
		return billId;
	}

	public void setBillId(Long billId) {
		this.billId = billId;
	}

	/**
	 * 产品ID
	 * @return
	 */
	public Integer getProductId() {
		return productId;
	}

	public void setProductId(Integer productId) {
		this.productId = productId;
	}

	/**
	 * 批号ID
	 * @return
	 */
	public Long getBatchNoId() {
		return batchNoId;
	}

	public void setBatchNoId(Long batchNoId) {
		this.batchNoId = batchNoId;
	}

	/**
	 * 存货地址ID
	 * @return
	 */
	public Integer getInvAddId() {
		return invAddId;
	}

	public void setInvAddId(Integer invAddId) {
		this.invAddId = invAddId;
	}

	/**
	 * 出入库方向
	 * @return
	 */
	public Integer getDirect() {
		return direct;
	}

	public void setDirect(Integer direct) {
		this.direct = direct;
	}

	/**
	 * 数量
	 * @return
	 */
	public BigDecimal getQuantity() {
		return quantity;
	}

	public void setQuantity(BigDecimal quantity) {
		this.quantity = quantity;
	}

	/**
	 * 税率
	 * @return
	 */
	public BigDecimal getTaxRate() {
		return taxRate;
	}

	public void setTaxRate(BigDecimal taxRate) {
		this.taxRate = taxRate;
	}

	/**
	 * 单价
	 * @return
	 */
	public BigDecimal getPrice() {
		return price;
	}

	public void setPrice(BigDecimal price) {
		this.price = price;
		this.settlePrice = price;
	}

	/**
	 * 结算单价
	 * @return
	 */
	public BigDecimal getSettlePrice() {
		return settlePrice;
	}

	public void setSettlePrice(BigDecimal settlePrice) {
		this.settlePrice = settlePrice;
	}

	/**
	 * 成本单价
	 * @return
	 */
	public BigDecimal getCostPrice() {
		return costPrice;
	}

	public void setCostPrice(BigDecimal costPrice) {
		this.costPrice = costPrice;
	}
	
	/**
	 * 明细金额
	 * @return
	 */
	public BigDecimal getAmount() {
		if(quantity == null || price == null) {
			return null;
		}
		return quantity.multiply(price);
	}

	/**
	 * 备注
	 * @return
	 */
	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	/**
	 * 产品信息
	 * @return
	 */
	public Product getProduct() {
		return product;
	}

	public void setProduct(Product product) {
		this.product = product;
		this.productId = product.getProductId();
	}

	/**
	 * 批号对象
	 * @return
	 */
	public ProductBatchNo getBatchNo() {
		return batchNo;
	}

	public void setBatchNo(ProductBatchNo batchNo) {
		this.batchNo = batchNo;
		this.batchNoId = batchNo.getId();
	}

	/**
	 * 存货地址对象
	 * @return
	 */
	public InventoryAdd getInvAdd() {
		return invAdd;
	}

	public void setInvAdd(InventoryAdd invAdd) {
		this.invAdd = invAdd;
		this.invAddId = invAdd.getId();
	}

	@Override
	public String toString() {
		ToStringBuilder sb = new ToStringBuilder(this, ToStringStyle.DEFAULT_STYLE);
		sb.append("id",this.id)
		  .append("billId",this.billId)
		  .append("invAddId",this.invAddId)
		  .append("productId",this.productId)
		  .append("batchNoId",this.batchNoId)
		  .append("quantity",this.quantity)
		  .append("price",this.price)
		  .append("settlePrice",this.settlePrice);
		
		return sb.toString();
	}

	@Override
	public boolean equals(Object o) {
		if(this == o) {
			return true;
		}
		if(!(o instanceof BillDetail)) {
			return false;
		}
		final BillDetail billDetail = (BillDetail)o;
		if(id != null) {
			return id.equals(billDetail.getId());
		} else {
			return billDetail.getId() == null;
		}
	}

	@Override
	public int hashCode() {
		return (this.id != null ? this.id.hashCode() : 0);
	}

}
